package main

var primes map[int]struct{}

func initPrimes(max int) {
	if primes != nil {
		return
	}
	m := make(map[int]struct{})
	for i := 2; i <= max; i++ {
		m[i] = struct{}{}
	}
	skip := make(map[int]struct{}) // no prime, skip
	for i := 2; i <= max; i++ {
		if _, ok := skip[i]; ok {
			continue
		}
		for j := 2; j <= max; j++ {
			v := i * j
			if v > max {
				break
			}
			delete(m, v)
			skip[v] = struct{}{}
		}
	}
	primes = m
}

func maximumPrimeDifference(nums []int) int {
	initPrimes(100)
	// find first
	first := -1
	for i, v := range nums {
		if _, ok := primes[v]; ok {
			first = i
			break
		}
	}
	last := -1
	for i := len(nums) - 1; i >= 0; i-- {
		v := nums[i]
		if _, ok := primes[v]; ok {
			last = i
			break
		}
	}
	return last - first
}

func main() {
	ret := maximumPrimeDifference([]int{4,2,9,5,3})
	println(ret)
}